import java.io.File;
import java.util.Calendar;


public class Reminder extends Thread{

	private Calendar rightNow;
	private ClipPlayer clip;
	private File file1 = new File("./gong.wav");
	private File file2 = new File("./bell.wav");
	private File file3 = new File("./dzwonek.wav");
	public Calendar getRightNow()
	{
		return this.rightNow;
	}
	public void rightNowDate()
	{
		this.rightNow.set(Calendar.HOUR_OF_DAY, 0);
		this.rightNow.set(Calendar.MINUTE, 0);
		this.rightNow.set(Calendar.SECOND,0);
		this.rightNow.set(Calendar.MILLISECOND, 0);
	}
	public Reminder()
	{
		super();
		this.rightNow = Calendar.getInstance();
		this.rightNow.set(Calendar.HOUR_OF_DAY, 0);
		this.rightNow.set(Calendar.MINUTE, 0);
		this.rightNow.set(Calendar.SECOND,0);
		this.rightNow.set(Calendar.MILLISECOND, 0);
	}
	public void run(Application a) throws InterruptedException
	{
		Calendar tmpTime;
		
		while (true)
		{
			if (a.getModel().isRemindOn())
			{
			for(int i=0;i<a.getModel().eventsList.size();i++)
			{
				rightNow = Calendar.getInstance();
				rightNowDate();
				if(rightNow.equals(a.getModel().eventsList.get(i).eventStartDate()) && !a.getModel().eventsList.get(i).isReminded() )
				{
					tmpTime = (Calendar)a.getModel().eventsList.get(i).getEventStart().clone();
					tmpTime.set(Calendar.MINUTE, tmpTime.get(Calendar.MINUTE)-a.getModel().eventsList.get(i).getRemind());
					rightNow = Calendar.getInstance();
					if(rightNow.after(tmpTime))
					{
						a.getModel().eventsList.get(i).setReminded(true);
						if (a.getModel().getSoundID()==1)
						clip = new ClipPlayer(file1,0);
						if (a.getModel().getSoundID()==2)
							clip = new ClipPlayer(file2,0);
						if (a.getModel().getSoundID()==3)
							clip = new ClipPlayer(file3,0);
					}
				}
			}
			}
			Thread.sleep(30000);
		}
		
		
	}
}
